<%--
  Created by IntelliJ IDEA.
  User: hongcy
  Date: 16-3-21
  Time: 下午2:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/include/taglib.jsp"%>
<% boolean isLoginError = request.getParameterMap().containsKey("login_error") ; %>
<!DOCTYPE html>
<html>
<head>
    <title>Business Login Page</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/datepicker3.css" rel="stylesheet">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/styles.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/html5shiv.min.js"></script>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        var ML = {
            alert: function (code, content) {
                var msg = [];
                if (code) {
                    msg.push(code);
                }
                if (content) {
                    msg.push(content);
                }
                alert(msg.join(":"));
            },
            defaultVal: function (val, defaultVal) {
                return val || defaultVal;
            }
        };
    </script>
</head>
<body>
    <div class="alert alert-info alert-dismissable" style="color:red ;text-align: center; display:none" id="error">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
            ×
        </button>
        账号或密码错误，请重试！
    </div>
    <div class="row" style="width:100%">
        <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">Login</div>
                <div class="panel-body">
                    <form id="form-login" role="form" action="${ctx}/mulanweb/common/login_out/sellerLogin" method="post">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="account" name="username" id="username" type="text" autofocus="">
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="password" name="password" id="password" type="password" value="" onkeydown="return keydown(event)">
                                <%--等于1表示电脑端，等于2表示移动端--%>
                                <input type="hidden" name="loginType" id="loginType" value="1"/>
                            </div>
                            <a id="btn-login" href="#" class="btn btn-primary">Submit</a>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div><!-- /.col-->
    </div><!-- /.row -->
    <script src="${cdnContentPath}/static/jquery/jquery-3.1.0.min.js"></script>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function keydown(e){
            if(e.keyCode==13){
                $("#btn-login").click() ;
            }
        }
        $(document).ready(function () {
            /*alert("浏览器版本："+navigator.appVersion);
            alert("浏览器类型："+navigator.appName);
            alert("操作系统："+typeof(navigator.platform)=="undefined"?"":navigator.platform);*/
            var MobileUA = (function() {
                var ua = navigator.userAgent.toLowerCase();

                var mua = {
                    IOS: /ipod|iphone|ipad/.test(ua), //iOS
                    IPHONE: /iphone/.test(ua), //iPhone
                    IPAD: /ipad/.test(ua), //iPad
                    ANDROID: /android/.test(ua), //Android Device
                    WINDOWS: /windows/.test(ua), //Windows Device
                    TOUCH_DEVICE: ('ontouchstart' in window) || /touch/.test(ua), //Touch Device
                    MOBILE: /mobile/.test(ua), //Mobile Device (iPad)
                    ANDROID_TABLET: false, //Android Tablet
                    WINDOWS_TABLET: false, //Windows Tablet
                    TABLET: false, //Tablet (iPad, Android, Windows)
                    SMART_PHONE: false //Smart Phone (iPhone, Android)
                };

                mua.ANDROID_TABLET = mua.ANDROID && !mua.MOBILE;
                mua.WINDOWS_TABLET = mua.WINDOWS && /tablet/.test(ua);
                mua.TABLET = mua.IPAD || mua.ANDROID_TABLET || mua.WINDOWS_TABLET;
                mua.SMART_PHONE = mua.MOBILE && !mua.TABLET;

                return mua;
            }());

            //SmartPhone
            if (MobileUA.SMART_PHONE) {
                // 移动端链接地址
                $("#loginType").val(2);
            }


            // 登陆页面要在最顶层窗口展示
            if(window.parent.location.href != window.location.href) {
                window.parent.location.href = window.location.href;
                return;
            }

            <%if (isLoginError) {%>
                $("#error").css("display","block") ;
            <%}%>
            var $username = $("#username"), $password = $("#password");
            $(document).on("keypress blur", "#username", function () {
                if ($username.val()) {
                    $username.parent().removeClass("has-error");
                } else {
                    $username.parent().addClass("has-error");
                }
            }).on("keypress blur", "#password", function () {
                if ($password.val()) {
                    $password.parent().removeClass("has-error");
                } else {
                    $password.parent().addClass("has-error");
                }
            }).on("click", "#btn-login", function () {
               var username = $username.val(), password = $password.val();
               if (!username) {
                   $username.parent().addClass("has-error").focus();
                   return false;
               } else {
                   $username.parent().removeClass("has-error");
               }
               if(!password) {
                   $password.parent().addClass("has-error").focus();
                   return false;
               } else {
                   $password.parent().removeClass("has-error");
               }

               $("#form-login").submit();
            })
        });
    </script>
</body>
</html>
